﻿using System.Web.Mvc;
using System.Web.Routing;

namespace Scribble.Web
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            new Container().Configure();
        }

        private static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        private static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("SiteRoot",
                            string.Empty,
                            new { controller = "Post", action = "Index" });

            routes.MapRoute("ListByTag",
                            "tags/{urlTitle}",
                            new { controller = "Post", action = "ListByTag" });

            routes.MapRoute("ListByCategory",
                            "categories/{urlTitle}",
                            new { controller = "Post", action = "ListByCategory" });

            routes.MapRoute("Post",
                            "{year}/{month}/{urlTitle}",
                            new { controller = "Post", action = "Get" },
                            new { year = @"\d{4}", month = @"\d{2}" });
        }
    }
}